﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using DataAccess.Base;
using DataAccess.Common;
using DataAccess.Entity;
using Interface.FormBuilder;
using Application.Common;
using System.Collections;
using DataAccess.Base;
using System.Runtime.InteropServices;


namespace BusinessProcess.FormBuilder
{
    [Serializable]
    public class BImportExportForms : ProcessBase, IImportExportForms
    {

        public DataSet GetAllFormDetail(string strFormStatus, string strTechArea, Int32 CountryId, string frmFormType)
        {

            ClsObject FormDetail = new ClsObject();
            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@FormStatus", SqlDbType.VarChar, strFormStatus);
            ClsUtility.AddParameters("@TechArea", SqlDbType.VarChar, strTechArea);
            ClsUtility.AddParameters("@CountryId", SqlDbType.VarChar, CountryId.ToString());
            if (frmFormType == "")
            {
                return (DataSet)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ManageForm_GetAllFormDetail_Futures", ClsUtility.ObjectEnum.DataSet);
            }
            else
            {
                return (DataSet)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ManageForm_GetAllHomeFormDetail_Futures", ClsUtility.ObjectEnum.DataSet);
            }
        }

        public DataSet GetImportExportFormDetail(String strFeatureName)
        {
            ClsObject CustomField = new ClsObject();
            DataSet dsRes;
            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@FeatureName", SqlDbType.VarChar, strFeatureName.ToString());
            dsRes = (DataSet)CustomField.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_FetchFormsDetail_Futures", ClsUtility.ObjectEnum.DataSet);
            return dsRes;
        }

        public DataSet GetImportExportHomeFormDetail(String strFeatureName)
        {
            ClsObject CustomField = new ClsObject();
            DataSet dsRes;
            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@FeatureName", SqlDbType.VarChar, strFeatureName.ToString());
            dsRes = (DataSet)CustomField.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_FetchHomeFormsDetail_Futures", ClsUtility.ObjectEnum.DataSet);
            return dsRes;
        }

        public int ImportForms(DataSet dsImportForms, int iUserId, int iCountryId)
        {
            try
            {
                this.Connection = DataMgr.GetConnection();
                this.Transaction = DataMgr.BeginTransaction(this.Connection);

                ClsObject FormDetail = new ClsObject();
                FormDetail.Connection = this.Connection;
                FormDetail.Transaction = this.Transaction;
                int theRowAffected = 0;
                DataRow theDR;

                int iNewFeatureId; //this variable will be used to store featureid for all new rows
                int iNewModuleId = 0;
                int iNewSectionId;
                int iNewFieldId = 0;
                int iNewConFieldId = 0;
                //string istrselectlstModecodeId = string.Empty;
                string strTableName = string.Empty;
                for (int j = 0; j < dsImportForms.Tables[5].Rows.Count; j++)
                {
                    if (dsImportForms.Tables[5].Rows[j].ItemArray[0].ToString() != "0")
                    {
                        ClsUtility.Init_Hashtable();
                        ClsUtility.AddParameters("@ModuleId", SqlDbType.Int, dsImportForms.Tables[5].Rows[j]["ModuleId"].ToString());
                        ClsUtility.AddParameters("@ModuleName", SqlDbType.VarChar, dsImportForms.Tables[5].Rows[j]["ModuleName"].ToString());
                        ClsUtility.AddParameters("@UserId", SqlDbType.Int, iUserId.ToString());
                        theDR = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportModules_Futures", ClsUtility.ObjectEnum.DataRow);
                        iNewModuleId = System.Convert.ToInt32(theDR[0].ToString());

                        DataView dvModuleFieldDV = new DataView();
                        dvModuleFieldDV = dsImportForms.Tables[6].DefaultView;
                        DataTable dtModuleField = new DataTable();
                        dvModuleFieldDV.RowFilter = "ModuleId=" + dsImportForms.Tables[5].Rows[j]["ModuleId"].ToString();
                        dtModuleField = dvModuleFieldDV.ToTable();
                        for (int k = 0; k < dtModuleField.Rows.Count; k++)
                        {
                            ClsUtility.Init_Hashtable();
                            ClsUtility.AddParameters("@ModuleId", SqlDbType.Int, iNewModuleId.ToString());
                            ClsUtility.AddParameters("@FieldId", SqlDbType.VarChar, dsImportForms.Tables[6].Rows[k]["Id"].ToString());
                            ClsUtility.AddParameters("@FieldName", SqlDbType.VarChar, dsImportForms.Tables[6].Rows[k]["FieldName"].ToString());
                            ClsUtility.AddParameters("@FieldType", SqlDbType.Int, dsImportForms.Tables[6].Rows[k]["FieldType"].ToString());
                            if (dsImportForms.Tables[6].Columns.Contains("label"))
                            {
                                ClsUtility.AddParameters("@Label", SqlDbType.VarChar, (dsImportForms.Tables[6].Rows[k]["label"].ToString() == null ? dsImportForms.Tables[6].Rows[k]["FieldName"].ToString() : dsImportForms.Tables[6].Rows[k]["label"].ToString()));
                            }
                            else
                                ClsUtility.AddParameters("@Label", SqlDbType.VarChar, dsImportForms.Tables[6].Rows[k]["FieldName"].ToString());
                            ClsUtility.AddParameters("@UserId", SqlDbType.Int, iUserId.ToString());
                            theDR = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportModulesIdentifier_Futures", ClsUtility.ObjectEnum.DataRow);
                            //iNewModuleId = System.Convert.ToInt32(theDR[0].ToString());
                        }
                    }
                }
                for (int i = 0; i < dsImportForms.Tables[0].Rows.Count; i++)
                {

                    string[] strFeatureName = new string[10];
                    strFeatureName = dsImportForms.Tables[0].Rows[i]["FeatureName"].ToString().Split(' ');
                    strTableName = "";
                    for (int j = 0; j < strFeatureName.Length; j++)
                    {
                        if (j > 0)
                            strTableName += "_" + strFeatureName[j];
                        else
                            strTableName += strFeatureName[j];

                    }
                    string strgridFeaturename = strTableName.ToString();
                    strTableName = "DTL_FBCUSTOMFIELD_" + strTableName;

                    //for modules and its identifiers
                    //modules-tech area's
                    ///Get New Module Id
                    if (dsImportForms.Tables[5].Rows[i].ItemArray[0].ToString() != "0")
                    {
                        DataRow[] foundRows = dsImportForms.Tables[5].Select("ModuleId=" + dsImportForms.Tables[0].Rows[i]["ModuleId"]);
                        string strModName = foundRows[0]["ModuleName"].ToString();
                        ClsUtility.Init_Hashtable();
                        ClsUtility.AddParameters("@ModuleName", SqlDbType.VarChar, strModName.ToString());
                        theDR = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_GetNewModuleId_Futures", ClsUtility.ObjectEnum.DataRow);
                        iNewModuleId = System.Convert.ToInt32(theDR[0].ToString());
                    }

                    //save mst_feature data
                    ClsUtility.Init_Hashtable();
                    ClsUtility.AddParameters("@FeatureId", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["FeatureId"].ToString());
                    ClsUtility.AddParameters("@FeatureName", SqlDbType.VarChar, dsImportForms.Tables[0].Rows[i]["FeatureName"].ToString());
                    ClsUtility.AddParameters("@ReportFlag", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["ReportFlag"].ToString());
                    ClsUtility.AddParameters("@DeleteFlag", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["DeleteFlag"].ToString());
                    ClsUtility.AddParameters("@AdminFlag", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["AdminFlag"].ToString());
                    //ClsUtility.AddParameters("@UserID", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["UserID"].ToString());
                    ClsUtility.AddParameters("@UserID", SqlDbType.Int, iUserId.ToString());
                    ClsUtility.AddParameters("@OptionalFlag", SqlDbType.Int, (dsImportForms.Tables[0].Columns.Contains("OptionalFlag")) ? dsImportForms.Tables[0].Rows[i]["OptionalFlag"].ToString() : "");
                    ClsUtility.AddParameters("@SystemId", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["SystemId"].ToString());
                    ClsUtility.AddParameters("@Published", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["Published"].ToString());
                    //ClsUtility.AddParameters("@CountryId", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["CountryId"].ToString());
                    ClsUtility.AddParameters("@CountryId", SqlDbType.Int, iCountryId.ToString());
                    ClsUtility.AddParameters("@ModuleId", SqlDbType.Int, iNewModuleId.ToString());
                    if (dsImportForms.Tables[0].Columns.Contains("MultiVisit"))
                    {
                        ClsUtility.AddParameters("@MultiVisit", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["MultiVisit"].ToString());
                    }
                    else
                    {
                        ClsUtility.AddParameters("@MultiVisit", SqlDbType.Int, "1");
                    }


                    theDR = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportForm_Futures", ClsUtility.ObjectEnum.DataRow);
                    iNewFeatureId = System.Convert.ToInt32(theDR[0].ToString());



                    //foreach (DataRow drFormData in dsSaveFormData.Tables[1])
                    for (int j = 0; j < dsImportForms.Tables[1].Rows.Count; j++)
                    {
                        if (dsImportForms.Tables[1].Rows[j]["FeatureId"].ToString() == dsImportForms.Tables[0].Rows[i]["FeatureId"].ToString())
                        {
                            ClsUtility.Init_Hashtable();
                            ClsUtility.AddParameters("@SectionId", SqlDbType.Int, dsImportForms.Tables[1].Rows[j]["SectionId"].ToString());
                            ClsUtility.AddParameters("@SectionName", SqlDbType.VarChar, dsImportForms.Tables[1].Rows[j]["SectionName"].ToString());
                            ClsUtility.AddParameters("@Seq", SqlDbType.Int, dsImportForms.Tables[1].Rows[j]["Seq"].ToString());
                            ClsUtility.AddParameters("@CustomFlag", SqlDbType.Int, dsImportForms.Tables[1].Rows[j]["CustomFlag"].ToString());
                            ClsUtility.AddParameters("@DeleteFlag", SqlDbType.Int, dsImportForms.Tables[1].Rows[j]["DeleteFlag"].ToString());
                            ClsUtility.AddParameters("@UserID", SqlDbType.Int, iUserId.ToString());
                            //ClsUtility.AddParameters("@FeatureId", SqlDbType.Int, dsImportForms.Tables[1].Rows[j]["FeatureId"].ToString());
                            ClsUtility.AddParameters("@FeatureId", SqlDbType.Int, iNewFeatureId.ToString());
                            ClsUtility.AddParameters("@IsGridView", SqlDbType.Int, (dsImportForms.Tables[1].Columns.Contains("IsGridView")) ? dsImportForms.Tables[1].Rows[j]["IsGridView"].ToString() : "0");
                           // ClsUtility.AddParameters("@IsGridView", SqlDbType.Int, dsImportForms.Tables[1].Rows[j]["IsGridView"].ToString());
                            theDR = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportSection_Futures", ClsUtility.ObjectEnum.DataRow);
                            iNewSectionId = System.Convert.ToInt32(theDR[0].ToString());
                            #region "Update/Insert Fields"
                            for (int x = 0; x < dsImportForms.Tables[2].Rows.Count; x++)
                            {
                                if (dsImportForms.Tables[1].Rows[j]["FeatureId"].ToString() == dsImportForms.Tables[2].Rows[x]["FeatureId"].ToString() && dsImportForms.Tables[1].Rows[j]["SectionId"].ToString() == dsImportForms.Tables[2].Rows[x]["SectionId"].ToString())
                                {
                                    //store comma separated select list val for field
                                    string strSelectLstVal = string.Empty;
                                    if (dsImportForms.Tables.Count > 3)
                                    {
                                        if (dsImportForms.Tables[3].Rows[0][0].ToString() != "0")
                                        {
                                            for (int l = 0; l < dsImportForms.Tables[3].Rows.Count; l++)
                                            {
                                                if (dsImportForms.Tables[3].Rows[l]["FeatureId"].ToString() == dsImportForms.Tables[2].Rows[x]["FeatureId"].ToString() && dsImportForms.Tables[3].Rows[l]["FieldId"].ToString() == dsImportForms.Tables[2].Rows[x]["FieldId"].ToString() && dsImportForms.Tables[3].Rows[l]["SectionId"].ToString() == dsImportForms.Tables[2].Rows[x]["SectionId"].ToString())
                                                {
                                                    if (strSelectLstVal == "")
                                                        strSelectLstVal = dsImportForms.Tables[3].Rows[l]["ListVal"].ToString();
                                                    else
                                                        strSelectLstVal = strSelectLstVal + ";" + dsImportForms.Tables[3].Rows[l]["ListVal"].ToString();
                                                }
                                            }
                                            //istrselectlstModecodeId = string.Empty;
                                            //for (int l = 0; l < dsImportForms.Tables[3].Rows.Count; l++)
                                            //{
                                            //    for (int t = 0; t < dsImportForms.Tables[7].Rows.Count; t++)
                                            //    {
                                            //        if (dsImportForms.Tables[3].Rows[l]["FeatureId"].ToString() == dsImportForms.Tables[7].Rows[t]["FeatureId"].ToString() && dsImportForms.Tables[3].Rows[l]["FieldId"].ToString() == dsImportForms.Tables[7].Rows[t]["FieldId"].ToString() && dsImportForms.Tables[3].Rows[l]["DecodeId"].ToString() == dsImportForms.Tables[7].Rows[t]["ConditionalFieldSectionId"].ToString() && dsImportForms.Tables[7].Rows[t]["fieldpredefined"].ToString() == "0")
                                            //        {
                                            //            if (istrselectlstModecodeId == "")
                                            //                istrselectlstModecodeId = dsImportForms.Tables[3].Rows[l]["ListVal"].ToString() + "-" + ((dsImportForms.Tables[7].Columns.Contains("ConditionalFieldSectionId") && dsImportForms.Tables[7].Rows[t]["ConditionalFieldSectionId"].ToString() != "") ? dsImportForms.Tables[7].Rows[t]["ConditionalFieldSectionId"].ToString() : "Null");
                                            //            else
                                            //                istrselectlstModecodeId = istrselectlstModecodeId + "," + dsImportForms.Tables[3].Rows[l]["ListVal"].ToString() + "-" + ((dsImportForms.Tables[4].Columns.Contains("ConditionalFieldSectionId") && dsImportForms.Tables[7].Rows[t]["ConditionalFieldSectionId"].ToString() != "") ? dsImportForms.Tables[7].Rows[t]["ConditionalFieldSectionId"].ToString() : "Null");
                                            //        }
                                            //    }
                                            //}
                                        }
                                    }

                                    //busrule id and val comma separated value, e.g. BusRuleId-Value(val used in case of min and max)
                                    string strBusRuleIdVal = string.Empty;
                                    if (dsImportForms.Tables.Count > 4)
                                    {
                                        if (dsImportForms.Tables[4].Rows[0][0].ToString() != "0")
                                        {
                                            for (int m = 0; m < dsImportForms.Tables[4].Rows.Count; m++)
                                            {
                                                if (dsImportForms.Tables[4].Rows[m]["FieldId"].ToString() == dsImportForms.Tables[2].Rows[x]["FieldId"].ToString() && dsImportForms.Tables[4].Rows[m]["Predefined"].ToString() == dsImportForms.Tables[2].Rows[x]["Predefined"].ToString())
                                                {
                                                    if (strBusRuleIdVal == "")
                                                        strBusRuleIdVal = dsImportForms.Tables[4].Rows[m]["BusRuleId"].ToString() + "-" + ((dsImportForms.Tables[4].Columns.Contains("Value") && dsImportForms.Tables[4].Rows[m]["Value"].ToString() != "") ? dsImportForms.Tables[4].Rows[m]["Value"].ToString() : "Null");
                                                    else
                                                        strBusRuleIdVal = strBusRuleIdVal + "," + dsImportForms.Tables[4].Rows[m]["BusRuleId"].ToString() + "-" + ((dsImportForms.Tables[4].Columns.Contains("Value") && dsImportForms.Tables[4].Rows[m]["Value"].ToString() != "") ? dsImportForms.Tables[4].Rows[m]["Value"].ToString() : "Null");
                                                }
                                            }
                                        }
                                    }

                                    ClsUtility.Init_Hashtable();
                                    ClsUtility.AddParameters("@Id", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["Id"].ToString());
                                    ClsUtility.AddParameters("@FeatureId", SqlDbType.Int, iNewFeatureId.ToString());
                                    ClsUtility.AddParameters("@SectionId", SqlDbType.Int, iNewSectionId.ToString());
                                    ClsUtility.AddParameters("@FieldId", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["FieldId"].ToString());
                                    ClsUtility.AddParameters("@FieldName", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["FieldName"].ToString());
                                    ClsUtility.AddParameters("@FieldLabel", SqlDbType.VarChar, dsImportForms.Tables[2].Rows[x]["FieldLabel"].ToString());
                                    ClsUtility.AddParameters("@ControlId", SqlDbType.Int, (dsImportForms.Tables[2].Columns.Contains("ControlId")) ? dsImportForms.Tables[2].Rows[x]["ControlId"].ToString() : "");
                                    ClsUtility.AddParameters("@SelectListVal", SqlDbType.VarChar, strSelectLstVal);
                                    ClsUtility.AddParameters("@BusRuleIdValAll", SqlDbType.VarChar, strBusRuleIdVal);
                                    ClsUtility.AddParameters("@Seq", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["Seq"].ToString());
                                    ClsUtility.AddParameters("@UserID", SqlDbType.Int, iUserId.ToString());
                                    ClsUtility.AddParameters("@Predefined", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["Predefined"].ToString());
                                    if (iNewFeatureId == 126)
                                    {
                                        ClsUtility.AddParameters("@PatientRegistration", SqlDbType.Int, "1");
                                    }
                                    //theRowAffected = (int)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportLnkForm_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);
                                    DataTable theFieldDT = (DataTable)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportLnkForm_Futures", ClsUtility.ObjectEnum.DataTable);
                                    if (theFieldDT.Rows.Count > 1)
                                    {
                                        DataView dvFieldDV = new DataView();
                                        dvFieldDV = theFieldDT.DefaultView;
                                        DataTable dtField = new DataTable();
                                        dvFieldDV.RowFilter = "FormFieldID <>'0'";
                                        dtField = dvFieldDV.ToTable();
                                        iNewFieldId = System.Convert.ToInt32(dtField.Rows[0][0].ToString());

                                    }
                                    else
                                        iNewFieldId = System.Convert.ToInt32(theFieldDT.Rows[0][0].ToString());
                                    if (dsImportForms.Tables[2].Rows[x]["Predefined"].ToString() != "1")
                                    {

                                        ClsUtility.Init_Hashtable();
                                        ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, strTableName);
                                        ClsUtility.AddParameters("@FieldName", SqlDbType.VarChar, dsImportForms.Tables[2].Rows[x]["FieldName"].ToString());
                                        ClsUtility.AddParameters("@DataType", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["ControlId"].ToString());
                                        ClsUtility.AddParameters("@Predefined", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["Predefined"].ToString());
                                        ClsUtility.AddParameters("@FieldId", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["FieldId"].ToString());
                                        theRowAffected = (int)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_FormBuilder_CustomTableCreation_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);
                                    }
                                    ///////Import GridView Control-Create Table//////////////////////////////////

                                    if (dsImportForms.Tables[1].Rows[j]["IsGridView"].ToString() == "1" && dsImportForms.Tables[2].Rows[x]["Predefined"].ToString() != "1")
                                    {
                                        string strTableNameSection = "DTL_CUSTOMFORM_" + dsImportForms.Tables[1].Rows[j]["SectionName"].ToString() + "_" + strgridFeaturename;
                                        ClsUtility.Init_Hashtable();
                                        ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, strTableNameSection);
                                        ClsUtility.AddParameters("@FieldName", SqlDbType.VarChar, dsImportForms.Tables[2].Rows[x]["FieldName"].ToString());
                                        ClsUtility.AddParameters("@DataType", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["ControlId"].ToString());
                                        ClsUtility.AddParameters("@FieldId", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["FieldId"].ToString());
                                        theRowAffected = (int)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_FormBuilder_CustomTableCreationGridView_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);
                                    }

                                    ////////Import Feild ICDCode Linking////////////////////////////////////////////
                                    if ((dsImportForms.Tables[11].Rows[0].ItemArray[0].ToString() != "0") && (dsImportForms.Tables[2].Rows[x]["ControlId"].ToString() == "16"))
                                    {
                                        DataView dvFilteredRow = new DataView();
                                        dvFilteredRow = dsImportForms.Tables[11].DefaultView;
                                        DataTable dtRow = new DataTable();
                                        dvFilteredRow.RowFilter = "FieldId='" + dsImportForms.Tables[2].Rows[x]["FieldId"].ToString() + "'";
                                        dtRow = dvFilteredRow.ToTable();
                                        if (dtRow.Rows.Count > 0)
                                        {
                                            if (dsImportForms.Tables[2].Rows[x]["FieldId"].ToString() == iNewFieldId.ToString())
                                            {
                                                ClsUtility.Init_Hashtable();
                                                ClsUtility.AddParameters("@FieldId", SqlDbType.Int, dsImportForms.Tables[2].Rows[x]["FieldId"].ToString());
                                                theRowAffected = (int)FormDetail.ReturnObject(ClsUtility.theParams, "pr_FormBuilder_DeleteFieldICDCode_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);
                                            }
                                            for (int q = 0; q < dtRow.Rows.Count; q++)
                                            {
                                                ClsUtility.Init_Hashtable();
                                                ClsUtility.AddParameters("@FieldId", SqlDbType.Int, iNewFieldId.ToString());
                                                ClsUtility.AddParameters("@BlockId", SqlDbType.Int, dtRow.Rows[q]["BlockId"].ToString());
                                                ClsUtility.AddParameters("@SubBlockId", SqlDbType.Int, dtRow.Rows[q]["SubBlockId"].ToString());
                                                ClsUtility.AddParameters("@CodeId", SqlDbType.Int, dtRow.Rows[q]["CodeId"].ToString());
                                                ClsUtility.AddParameters("@UserId", SqlDbType.Int, dtRow.Rows[q]["UserId"].ToString());
                                                ClsUtility.AddParameters("@DeleteFlag", SqlDbType.Int, "0");
                                                ClsUtility.AddParameters("@Predefined", SqlDbType.Int, dtRow.Rows[q]["Predefined"].ToString());
                                                theRowAffected = (int)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_FormBuilder_SaveICD10CodeItems_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

                                            }
                                        }


                                    }
                                    ///////////////////////////////////////////////////
                                    #region "Update/Insert Conditional Fields"
                                    if (dsImportForms.Tables.Count > 7)
                                    {
                                        if (dsImportForms.Tables[7].Rows.Count > 0)
                                        {
                                            if (dsImportForms.Tables[7].Rows[0][0].ToString() != "")
                                            {
                                                if (dsImportForms.Tables[7].Rows[0][0].ToString() != "0")
                                                {
                                                    for (int n = 0; n < dsImportForms.Tables[7].Rows.Count; n++)
                                                    {
                                                        if (dsImportForms.Tables[1].Rows[j]["FeatureId"].ToString() == dsImportForms.Tables[7].Rows[n]["FeatureId"].ToString() && dsImportForms.Tables[1].Rows[j]["SectionId"].ToString() == dsImportForms.Tables[7].Rows[n]["SectionId"].ToString())
                                                        {
                                                            //store comma separated select list val for field
                                                            string strConSelectLstVal = string.Empty;
                                                            if (dsImportForms.Tables.Count > 8)
                                                            {
                                                                if (dsImportForms.Tables[8].Rows[0][0].ToString() != "0")
                                                                {
                                                                    for (int l = 0; l < dsImportForms.Tables[8].Rows.Count; l++)
                                                                    {
                                                                        if (dsImportForms.Tables[8].Rows[l]["FeatureId"].ToString() == dsImportForms.Tables[7].Rows[n]["FeatureId"].ToString() && dsImportForms.Tables[8].Rows[l]["FieldId"].ToString() == dsImportForms.Tables[7].Rows[n]["ConditionalFieldId"].ToString() && dsImportForms.Tables[8].Rows[l]["SectionId"].ToString() == dsImportForms.Tables[7].Rows[n]["ConditionalFieldSectionId"].ToString())
                                                                        {
                                                                            if (strConSelectLstVal == "")
                                                                                strConSelectLstVal = dsImportForms.Tables[8].Rows[l]["ListVal"].ToString();
                                                                            else
                                                                                strConSelectLstVal = strConSelectLstVal + ";" + dsImportForms.Tables[8].Rows[l]["ListVal"].ToString();
                                                                        }
                                                                    }
                                                                }
                                                            }

                                                            //busrule id and val comma separated value, e.g. BusRuleId-Value(val used in case of min and max)
                                                            string strConBusRuleIdVal = string.Empty;
                                                            if (dsImportForms.Tables.Count > 9)
                                                            {
                                                                if (dsImportForms.Tables[9].Rows[0][0].ToString() != "0")
                                                                {
                                                                    for (int z = 0; z < dsImportForms.Tables[9].Rows.Count; z++)
                                                                    {
                                                                        if (dsImportForms.Tables[9].Rows[z]["FieldId"].ToString() == dsImportForms.Tables[7].Rows[n]["ConditionalFieldId"].ToString() && dsImportForms.Tables[9].Rows[z]["Predefined"].ToString() == dsImportForms.Tables[7].Rows[n]["ConditionalFieldPredefined"].ToString())
                                                                        {
                                                                            if (strConBusRuleIdVal == "")
                                                                                strConBusRuleIdVal = dsImportForms.Tables[9].Rows[z]["BusRuleId"].ToString() + "-" + ((dsImportForms.Tables[4].Columns.Contains("Value") && dsImportForms.Tables[9].Rows[z]["Value"].ToString() != "") ? dsImportForms.Tables[9].Rows[z]["Value"].ToString() : "Null") + "-" + ((dsImportForms.Tables[4].Columns.Contains("Value1") && dsImportForms.Tables[9].Rows[z]["Value1"].ToString() != "") ? dsImportForms.Tables[9].Rows[z]["Value1"].ToString() : "Null");
                                                                            else
                                                                                strConBusRuleIdVal = strConBusRuleIdVal + "," + dsImportForms.Tables[9].Rows[z]["BusRuleId"].ToString() + "-" + ((dsImportForms.Tables[9].Columns.Contains("Value") && dsImportForms.Tables[9].Rows[z]["Value"].ToString() != "") ? dsImportForms.Tables[9].Rows[z]["Value"].ToString() : "Null") + "-" + ((dsImportForms.Tables[9].Columns.Contains("Value1") && dsImportForms.Tables[9].Rows[z]["Value1"].ToString() != "") ? dsImportForms.Tables[9].Rows[z]["Value1"].ToString() : "Null");
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            if (dsImportForms.Tables[2].Rows[x]["fieldId"].ToString() == dsImportForms.Tables[7].Rows[n]["FieldId"].ToString() && dsImportForms.Tables[2].Rows[x]["SectionId"].ToString() == dsImportForms.Tables[7].Rows[n]["SectionId"].ToString() && dsImportForms.Tables[2].Rows[x]["featureId"].ToString() == dsImportForms.Tables[7].Rows[n]["featureId"].ToString())
                                                            {
                                                                ClsUtility.Init_Hashtable();
                                                                ClsUtility.AddParameters("@FeatureId", SqlDbType.Int, iNewFeatureId.ToString());
                                                                ClsUtility.AddParameters("@SectionId", SqlDbType.Int, iNewSectionId.ToString());
                                                                ClsUtility.AddParameters("@FieldId", SqlDbType.Int, iNewFieldId.ToString());
                                                                ClsUtility.AddParameters("@FieldName", SqlDbType.VarChar, dsImportForms.Tables[7].Rows[n]["FieldName"].ToString());
                                                                ClsUtility.AddParameters("@ConFieldId", SqlDbType.Int, dsImportForms.Tables[7].Rows[n]["ConditionalFieldId"].ToString());
                                                                ClsUtility.AddParameters("@ConFieldName", SqlDbType.Int, dsImportForms.Tables[7].Rows[n]["ConditionalFieldName"].ToString());
                                                                ClsUtility.AddParameters("@ConFieldLabel", SqlDbType.VarChar, dsImportForms.Tables[7].Rows[n]["ConditionalFieldLabel"].ToString());
                                                                ClsUtility.AddParameters("@ControlId", SqlDbType.VarChar, dsImportForms.Tables[7].Rows[n]["ControlId"].ToString());
                                                                ClsUtility.AddParameters("@ConControlId", SqlDbType.Int, (dsImportForms.Tables[7].Columns.Contains("ConditionalFieldControlId")) ? dsImportForms.Tables[7].Rows[n]["ConditionalFieldControlId"].ToString() : "");
                                                                ClsUtility.AddParameters("@ConSelectListVal", SqlDbType.VarChar, strConSelectLstVal);
                                                                ClsUtility.AddParameters("@ConBusRuleIdValAll", SqlDbType.VarChar, strConBusRuleIdVal);
                                                                ClsUtility.AddParameters("@ConSeq", SqlDbType.Int, dsImportForms.Tables[7].Rows[n]["ConditionalFieldSequence"].ToString());
                                                                ClsUtility.AddParameters("@UserID", SqlDbType.Int, iUserId.ToString());
                                                                ClsUtility.AddParameters("@ConPredefined", SqlDbType.Int, dsImportForms.Tables[7].Rows[n]["ConditionalFieldPredefined"].ToString());
                                                                ClsUtility.AddParameters("@Predefined", SqlDbType.Int, dsImportForms.Tables[7].Rows[n]["fieldpredefined"].ToString());
                                                                ClsUtility.AddParameters("@ConSectionId", SqlDbType.Int, dsImportForms.Tables[7].Rows[n]["ConditionalFieldSectionId"].ToString());
                                                                ClsUtility.AddParameters("@ModdecodeName", SqlDbType.VarChar, dsImportForms.Tables[7].Rows[n]["Mod"].ToString());
                                                                ClsUtility.AddParameters("@SystemId", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["SystemId"].ToString());
                                                                //theRowAffected = (int)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportLnkForm_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);
                                                                if (iNewFeatureId == 126)
                                                                {
                                                                    theDR = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportRegistrationConditionalField_Futures", ClsUtility.ObjectEnum.DataRow);
                                                                }
                                                                else
                                                                {
                                                                    theDR = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportConditionalField_Futures", ClsUtility.ObjectEnum.DataRow);
                                                                }
                                                                iNewConFieldId = System.Convert.ToInt32(theDR[0].ToString());

                                                                if (dsImportForms.Tables[7].Rows[n]["ConditionalFieldPredefined"].ToString() != "1")
                                                                {

                                                                    ClsUtility.Init_Hashtable();
                                                                    ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, strTableName);
                                                                    ClsUtility.AddParameters("@FieldName", SqlDbType.VarChar, dsImportForms.Tables[7].Rows[n]["ConditionalFieldName"].ToString());
                                                                    ClsUtility.AddParameters("@DataType", SqlDbType.Int, dsImportForms.Tables[7].Rows[n]["ConditionalFieldControlId"].ToString());
                                                                    ClsUtility.AddParameters("@Predefined", SqlDbType.Int, dsImportForms.Tables[7].Rows[n]["ConditionalFieldPredefined"].ToString());
                                                                    ClsUtility.AddParameters("@FieldId", SqlDbType.Int, iNewConFieldId.ToString());
                                                                    theRowAffected = (int)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_FormBuilder_CustomTableCreation_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);
                                                                }
                                                            }


                                                        }
                                                    }
                                                }
                                            }//0 closed
                                        }
                                    }
                                    #endregion

                                }//feature id and section id if condition closes here

                            }
                            #endregion

                        }
                    }



                }

                DataMgr.CommitTransaction(this.Transaction);
                DataMgr.ReleaseConnection(this.Connection);
                //return iFeatureId;
                return 1;
            }
            catch
            {
                DataMgr.RollBackTransation(this.Transaction);
                throw;
            }
            finally
            {
                if (this.Connection != null)
                    DataMgr.ReleaseConnection(this.Connection);

            }
        }


        //import home forms
        public int ImportHomeForms(DataSet dsImportForms, int iUserId, int iCountryId)
        {
            try
            {
                this.Connection = DataMgr.GetConnection();
                this.Transaction = DataMgr.BeginTransaction(this.Connection);

                ClsObject FormDetail = new ClsObject();
                FormDetail.Connection = this.Connection;
                FormDetail.Transaction = this.Transaction;

                DataRow theDR;

                int iNewFeatureId; //this variable will be used to store featureid for all new rows

                string strTableName = string.Empty;

                for (int i = 0; i < dsImportForms.Tables[0].Rows.Count; i++)
                {

                    //string[] strFeatureName = new string[10];
                    //strFeatureName = dsImportForms.Tables[0].Rows[i]["FeatureName"].ToString().Split(' ');
                    //strTableName = "";
                    //for (int j = 0; j < strFeatureName.Length; j++)
                    //{
                    //    if (j > 0)
                    //        strTableName += "_" + strFeatureName[j];
                    //    else
                    //        strTableName += strFeatureName[j];

                    //}
                    //strTableName = "DTL_FBCUSTOMFIELD_" + strTableName;

                    //save mst_feature data
                    ClsUtility.Init_Hashtable();
                    ClsUtility.AddParameters("@FeatureId", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["FeatureId"].ToString());
                    ClsUtility.AddParameters("@FeatureName", SqlDbType.VarChar, dsImportForms.Tables[0].Rows[i]["FeatureName"].ToString());
                    ClsUtility.AddParameters("@ReportFlag", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["ReportFlag"].ToString());
                    ClsUtility.AddParameters("@DeleteFlag", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["DeleteFlag"].ToString());
                    ClsUtility.AddParameters("@AdminFlag", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["AdminFlag"].ToString());
                    //ClsUtility.AddParameters("@UserID", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["UserID"].ToString());
                    ClsUtility.AddParameters("@UserID", SqlDbType.Int, iUserId.ToString());
                    ClsUtility.AddParameters("@OptionalFlag", SqlDbType.Int, (dsImportForms.Tables[0].Columns.Contains("OptionalFlag")) ? dsImportForms.Tables[0].Rows[i]["OptionalFlag"].ToString() : "");
                    ClsUtility.AddParameters("@SystemId", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["SystemId"].ToString());
                    ClsUtility.AddParameters("@Published", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["Published"].ToString());
                    //ClsUtility.AddParameters("@CountryId", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["CountryId"].ToString());
                    ClsUtility.AddParameters("@CountryId", SqlDbType.Int, iCountryId.ToString());
                    ClsUtility.AddParameters("@ModuleId", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["ModuleId"].ToString());
                    if (dsImportForms.Tables[0].Columns.Contains("MultiVisit"))
                        ClsUtility.AddParameters("@MultiVisit", SqlDbType.Int, dsImportForms.Tables[0].Rows[i]["MultiVisit"].ToString());

                    theDR = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportHomeForm_Futures", ClsUtility.ObjectEnum.DataRow);
                    iNewFeatureId = System.Convert.ToInt32(theDR[0].ToString());

                    //for home page and its dtl
                    //
                    for (int j = 0; j < dsImportForms.Tables[1].Rows.Count; j++)
                    {
                        int iHomePageId;
                        ClsUtility.Init_Hashtable();

                        ClsUtility.AddParameters("@HomePageName", SqlDbType.VarChar, dsImportForms.Tables[1].Rows[j]["Name"].ToString());
                        ClsUtility.AddParameters("@FeatureId", SqlDbType.Int, iNewFeatureId.ToString());
                        ClsUtility.AddParameters("@UserID", SqlDbType.Int, iUserId.ToString());
                        theDR = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportMstHomePage_Futures", ClsUtility.ObjectEnum.DataRow);
                        iHomePageId = System.Convert.ToInt32(theDR[0].ToString());

                        for (int k = 0; k < dsImportForms.Tables[2].Rows.Count; k++)
                        {
                            ClsUtility.Init_Hashtable();
                            ClsUtility.AddParameters("@HomePageId", SqlDbType.Int, iHomePageId.ToString());
                            ClsUtility.AddParameters("@IndicatorName", SqlDbType.VarChar, dsImportForms.Tables[2].Rows[k]["IndicatorName"].ToString());
                            if (dsImportForms.Tables[2].Columns.Contains("Query"))
                                ClsUtility.AddParameters("@Query", SqlDbType.VarChar, dsImportForms.Tables[2].Rows[k]["Query"].ToString());

                            ClsUtility.AddParameters("@Seq", SqlDbType.Int, dsImportForms.Tables[2].Rows[k]["Seq"].ToString());
                            ClsUtility.AddParameters("@UserId", SqlDbType.Int, iUserId.ToString());
                            theDR = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportExportForms_ImportdtlHomePage_Futures", ClsUtility.ObjectEnum.DataRow);
                            //iNewModuleId = System.Convert.ToInt32(theDR[0].ToString());
                        }
                    }
                }



                DataMgr.CommitTransaction(this.Transaction);
                DataMgr.ReleaseConnection(this.Connection);
                //return iFeatureId;
                return 1;
            }
            catch
            {
                DataMgr.RollBackTransation(this.Transaction);
                throw;
            }
            finally
            {
                if (this.Connection != null)
                    DataMgr.ReleaseConnection(this.Connection);

            }
        }

        //Import Patient Data
        public DataTable ImportPatientData(DataSet dsImportPatData, int iUserId, int iSystemId)
        {
            try
            {
                this.Connection = DataMgr.GetConnection();
                this.Transaction = DataMgr.BeginTransaction(this.Connection);

                ClsObject FormDetail = new ClsObject();
                FormDetail.Connection = this.Connection;
                FormDetail.Transaction = this.Transaction;
                int theRowAffected = 0;
                DataRow theDR;
                DataTable DT = new DataTable();

                SqlConnection cnn;

                if (null == this.Connection)
                {
                    cnn = (SqlConnection)DataMgr.GetConnection();
                }
                else
                {
                    cnn = (SqlConnection)this.Connection;
                }

                int iNewPatientId; //this variable will be used to store Patientid for all new rows
                int iNewModuleId = 0;
                int iNewSectionId;
                int iNewFieldId = 0;
                int iNewConFieldId = 0;
                int iOldPtn_Pharmacy_Pk = 0;
                int iOldLabID = 0;
                int iOldTrackingId = 0;
                int iOldCareEnded = 0;
                //string istrselectlstModecodeId = string.Empty;
                string strTableName = string.Empty;
                DataTable dtpattab = new DataTable();
                DataRow drpatrow;
                string xmlString = string.Empty;
                MemoryStream s;
                StreamReader sr;
                DataTable theDTFilteredMstModuleName = new DataTable();
                ClsUtility.Init_Hashtable();
                ClsUtility.AddParameters("@UserId", SqlDbType.Int, iUserId.ToString());
                ClsUtility.AddParameters("@SystemId", SqlDbType.Int, iSystemId.ToString());
                DataSet DSVisitTypes = (DataSet)FormDetail.ReturnObject(ClsUtility.theParams, "pr_FormBuilder_GetCustomVisitType_Futures", ClsUtility.ObjectEnum.DataSet);
                DataSet DSPharmacy = GetDSbyColumnName(dsImportPatData, "Ptn_pharmacy_pk", false);
                //if (DSPharmacy.Tables.Contains("ORD_PATIENTPHARMACYORDER"))
                //{
                //    DSPharmacy.Tables.Remove(dsImportPatData.Tables["ORD_PATIENTPHARMACYORDER"]);

                //}
                DataSet DSLaboratory = GetDSbyColumnName(dsImportPatData, "LabID", false);
                //if (DSLaboratory.Tables.Contains("ORD_PATIENTLABORDER"))
                //{
                //    DSLaboratory.Tables.Remove(dsImportPatData.Tables["ORD_PATIENTLABORDER"]);

                //}
                if (dsImportPatData.Tables["MST_PATIENT"].Rows.Count > 0)
                {
                    s = new MemoryStream();
                    dsImportPatData.Tables["MST_PATIENT"].WriteXml(s, true);
                    //Retrieve the text from the stream
                    s.Seek(0, SeekOrigin.Begin);
                    sr = new StreamReader(s);
                    xmlString = sr.ReadToEnd();
                    //close
                    sr.Close();
                    sr.Dispose();
                    s.Dispose();
                    dsImportPatData.Tables.Remove(dsImportPatData.Tables["MST_PATIENT"]);
                    dsImportPatData.Tables.Remove(dsImportPatData.Tables["APPADMIN"]);
                    ClsUtility.Init_Hashtable();
                    ClsUtility.AddParameters("@xmlrow", SqlDbType.Xml, xmlString.ToString());
                    ClsUtility.AddParameters("@UserId", SqlDbType.Int, iUserId.ToString());
                    ClsUtility.AddParameters("@password", SqlDbType.VarChar, ApplicationAccess.DBSecurity);
                    DT = (DataTable)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientInfo_Futures", ClsUtility.ObjectEnum.DataTable);
                    //iNewModuleId = System.Convert.ToInt32(theDR[0].ToString());

                    string theOtherColName;
                    StringBuilder strInsert = new StringBuilder();
                    DataRow row;

                    for (int j = 0; j < DT.Rows.Count; j++)
                    {
                        DataView theIdentifierDV = new DataView(dsImportPatData.Tables["PATIENTIDENTIFIERVALUE"]);
                        theIdentifierDV.RowFilter = "Ptn_pk=" + DT.Rows[j]["OldPtn_Pk"].ToString();
                        DataTable theFilteredIdentifier = CreateTableFromDataView(theIdentifierDV);
                        foreach (DataRow DRIdentifier in theFilteredIdentifier.Rows)
                        {
                            strInsert = new StringBuilder("");
                            foreach (DataColumn Identifiercol in theFilteredIdentifier.Columns)
                            {
                                //test for null here
                                if (DRIdentifier[Identifiercol] == DBNull.Value || DRIdentifier[Identifiercol].ToString() == "")
                                {

                                    strInsert.Append(Identifiercol.ColumnName + "-NULL;");

                                }
                                else
                                {
                                    if (Identifiercol.ColumnName.ToString() != "UpdateDate")
                                    {
                                        if (Identifiercol.ColumnName.ToString() == "CreateDate")
                                        {
                                            strInsert.Append(Identifiercol.ColumnName + "-getdate();");

                                        }
                                        else
                                        {
                                            if (DRIdentifier[Identifiercol].ToString().IndexOf("+05:30") > 0)
                                            {
                                                string str2 = DRIdentifier[Identifiercol].ToString().Substring(0, DRIdentifier[Identifiercol].ToString().IndexOf("T"));
                                                str2 = str2.Replace("-", "/");
                                                strInsert.Append(Identifiercol.ColumnName + "-" + str2.ToString() + ";");
                                            }
                                            else
                                                strInsert.Append(Identifiercol.ColumnName + "-" + DRIdentifier[Identifiercol].ToString() + ";");
                                        }
                                    }

                                }

                            }
                            ClsUtility.Init_Hashtable();
                            ClsUtility.AddParameters("@strinsert", SqlDbType.VarChar, strInsert.ToString());
                            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, theFilteredIdentifier.TableName.ToString());
                            ClsUtility.AddParameters("@NewPtn_Pk", SqlDbType.Int, DT.Rows[j]["NewPtn_Pk"].ToString());
                            DataRow DRModule_ID = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientIdentifier_Futures", ClsUtility.ObjectEnum.DataRow);
                        }

                        DataView thelnkProgDV = new DataView(dsImportPatData.Tables["LNK_PATIENTPROGRAMSTART"]);
                        thelnkProgDV.RowFilter = "Ptn_pk=" + DT.Rows[j]["OldPtn_Pk"].ToString();
                        DataTable theFilteredlnkProg = CreateTableFromDataView(thelnkProgDV);
                        foreach (DataRow DRLnkProg in theFilteredlnkProg.Rows)
                        {
                            strInsert = new StringBuilder("");
                            if (DSVisitTypes.Tables[1].Rows.Count > 0)
                            {
                                DataView theMstModuleDV = new DataView(dsImportPatData.Tables["MST_MODULE"]);
                                theMstModuleDV.RowFilter = "ModuleId=" + DRLnkProg["ModuleId"].ToString();
                                DataTable theFilteredMstModuleDT = CreateTableFromDataView(theMstModuleDV);
                                if (theFilteredMstModuleDT.Rows.Count > 0)
                                {
                                    DataView theFilteredMstModuleDV = new DataView(DSVisitTypes.Tables[1]);
                                    theFilteredMstModuleDV.RowFilter = "ModuleName='" + theFilteredMstModuleDT.Rows[0]["ModuleName"].ToString() + "'";
                                    theDTFilteredMstModuleName = CreateTableFromDataView(theFilteredMstModuleDV);
                                }
                            }
                            foreach (DataColumn LnkProgcol in theFilteredlnkProg.Columns)
                            {
                                //test for null here
                                if (DRLnkProg[LnkProgcol] == DBNull.Value || DRLnkProg[LnkProgcol].ToString() == "")
                                {

                                    strInsert.Append(LnkProgcol.ColumnName + "-NULL;");

                                }
                                else
                                {
                                    if (LnkProgcol.ColumnName.ToString() != "UpdateDate")
                                    {
                                        if (LnkProgcol.ColumnName.ToString() == "CreateDate")
                                        {
                                            strInsert.Append(LnkProgcol.ColumnName + "-getdate();");

                                        }
                                        else
                                        {
                                            if (DRLnkProg[LnkProgcol].ToString().IndexOf("+05:30") > 0)
                                            {
                                                string str2 = DRLnkProg[LnkProgcol].ToString().Substring(0, DRLnkProg[LnkProgcol].ToString().IndexOf("T"));
                                                str2 = str2.Replace("-", "/");
                                                strInsert.Append(LnkProgcol.ColumnName + "-" + str2.ToString() + ";");
                                            }
                                            else
                                                strInsert.Append(LnkProgcol.ColumnName + "-" + DRLnkProg[LnkProgcol].ToString() + ";");
                                        }
                                    }

                                }

                            }
                            ClsUtility.Init_Hashtable();
                            ClsUtility.AddParameters("@strinsert", SqlDbType.VarChar, strInsert.ToString());
                            ClsUtility.AddParameters("@Visit_pk", SqlDbType.Int, theDTFilteredMstModuleName.Rows[0]["ModuleId"].ToString());
                            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, theFilteredlnkProg.TableName.ToString());
                            ClsUtility.AddParameters("@NewPtn_Pk", SqlDbType.Int, DT.Rows[j]["NewPtn_Pk"].ToString());
                            ClsUtility.AddParameters("@VisitColumn", SqlDbType.VarChar, "ModuleId");
                            ClsUtility.AddParameters("@password", SqlDbType.VarChar, ApplicationAccess.DBSecurity);
                            DataRow DRModule_ID = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientTableData_Futures", ClsUtility.ObjectEnum.DataRow);

                        }
                        //if (dsImportPatData.Tables.Contains("MST_MODULE"))
                        //{
                        //    dsImportPatData.Tables.Remove(dsImportPatData.Tables["MST_MODULE"]);
                        //}
                        //if(dsImportPatData.Tables.Contains("LNK_PATIENTPROGRAMSTART"))
                        //{
                        //    dsImportPatData.Tables.Remove(dsImportPatData.Tables["LNK_PATIENTPROGRAMSTART"]);
                        //}


                        DataView theOrdvisitDV = new DataView(dsImportPatData.Tables["ORD_VISIT"]);
                        theOrdvisitDV.RowFilter = "Ptn_pk=" + DT.Rows[j]["OldPtn_Pk"].ToString();
                        DataTable theFilteredOrdDT = CreateTableFromDataView(theOrdvisitDV);
                        for (int k = 0; k < theFilteredOrdDT.Rows.Count; k++)
                        {
                            row = theFilteredOrdDT.Rows[k];
                            strInsert = new StringBuilder("");
                            DataTable theDTFilteredMstVisitName = new DataTable();
                            if (Convert.ToInt32(row["Visittype"]) > 100)
                            {
                                if (DSVisitTypes.Tables[0].Rows.Count > 0)
                                {
                                    DataView theMstvisitDV = new DataView(dsImportPatData.Tables["MST_VISITTYPE"]);
                                    theMstvisitDV.RowFilter = "VisittypeId=" + row["Visittype"].ToString();
                                    DataTable theFilteredMstvisitypeDT = CreateTableFromDataView(theMstvisitDV);

                                    DataView theFilteredMstvisitDV = new DataView(DSVisitTypes.Tables[0]);
                                    theFilteredMstvisitDV.RowFilter = "VisitName='" + theFilteredMstvisitypeDT.Rows[0]["VisitName"].ToString() + "'";
                                    theDTFilteredMstVisitName = CreateTableFromDataView(theFilteredMstvisitDV);

                                }
                            }
                            foreach (DataColumn col in theFilteredOrdDT.Columns)
                            {
                                //test for null here
                                if (row[col] == DBNull.Value || row[col].ToString() == "")
                                {

                                    strInsert.Append(col.ColumnName + "-NULL;");

                                }
                                else
                                {
                                    if (col.ColumnName.ToString() != "UpdateDate")
                                    {
                                        if (col.ColumnName.ToString() == "CreateDate")
                                        {
                                            strInsert.Append(col.ColumnName + "-getdate();");

                                        }
                                        else
                                        {
                                            if (row[col].ToString().IndexOf("+05:30") > 0)
                                            {
                                                string str2 = row[col].ToString().Substring(0, row[col].ToString().IndexOf("T"));
                                                str2 = str2.Replace("-", "/");
                                                strInsert.Append(col.ColumnName + "-" + str2.ToString() + ";");
                                            }
                                            else
                                                strInsert.Append(col.ColumnName + "-" + row[col].ToString() + ";");
                                        }
                                    }

                                }

                            }
                            ClsUtility.Init_Hashtable();
                            ClsUtility.AddParameters("@strinsert", SqlDbType.VarChar, strInsert.ToString());
                            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, theFilteredOrdDT.TableName.ToString());
                            if (Convert.ToInt32(row["Visittype"]) > 100)
                            {
                                ClsUtility.AddParameters("@VisitTypParamValue", SqlDbType.Int, theDTFilteredMstVisitName.Rows[0]["VisittypeID"].ToString());
                            }
                            ClsUtility.AddParameters("@NewPtn_Pk", SqlDbType.Int, DT.Rows[j]["NewPtn_Pk"].ToString());
                            ClsUtility.AddParameters("@VisitColumn", SqlDbType.VarChar, "Visit_Id");
                            ClsUtility.AddParameters("@password", SqlDbType.VarChar, ApplicationAccess.DBSecurity);
                            DataRow DRVisit_ID = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientTableData_Futures", ClsUtility.ObjectEnum.DataRow);
                            DataSet DSVisitId = GetDSbyColumnName(dsImportPatData, "Visit", true);
                            if (DSVisitId.Tables.Count > 0)
                            {
                                if (Convert.ToInt32(DRVisit_ID["Visit_Id"]) > 0)
                                {
                                    foreach (DataTable dtothers in DSVisitId.Tables)
                                    {
                                        theOtherColName = string.Empty;
                                        if (dtothers.TableName.ToString() != "ORD_VISIT" && dtothers.TableName.ToString() != "LNK_PATIENTPROGRAMSTART" && dtothers.TableName.ToString() != "MST_VISITTYPE")
                                        {
                                            foreach (DataColumn dcvisit in dtothers.Columns)
                                            {
                                                if (dcvisit.ColumnName.StartsWith("Visit") && dcvisit.ColumnName.ToString().ToUpper() != "VISITNAME")
                                                {
                                                    theOtherColName = dcvisit.ColumnName.ToString();
                                                }
                                            }

                                            DataView theOtherDV = new DataView(dtothers);
                                            theOtherDV.RowFilter = theOtherColName.ToString() + " = " + theFilteredOrdDT.Rows[k]["Visit_Id"].ToString();
                                            DataTable theOtherDT = CreateTableFromDataView(theOtherDV);
                                            if (theOtherDT.Rows.Count > 0)
                                            {

                                                foreach (DataRow rowothers in theOtherDT.Rows)
                                                {
                                                    strInsert = new StringBuilder("");
                                                    foreach (DataColumn colothers in theOtherDT.Columns)
                                                    {
                                                        if (rowothers[colothers] == DBNull.Value || rowothers[colothers].ToString() == "")
                                                        {

                                                            strInsert.Append(colothers.ColumnName + "-NULL;");

                                                        }
                                                        else
                                                        {
                                                            if (colothers.ColumnName.ToString() != "UpdateDate")
                                                            {
                                                                if (colothers.ColumnName.ToString() == "CreateDate")
                                                                {
                                                                    strInsert.Append(colothers.ColumnName + "-getdate();");

                                                                }
                                                                else
                                                                {
                                                                    if (rowothers[colothers].ToString().IndexOf("+05:30") > 0)
                                                                    {
                                                                        string str3 = rowothers[colothers].ToString().Substring(0, rowothers[colothers].ToString().IndexOf("T"));
                                                                        str3 = str3.Replace("-", "/");
                                                                        strInsert.Append(colothers.ColumnName + "-" + str3.ToString() + ";");
                                                                    }
                                                                    else
                                                                    {
                                                                        if (rowothers[colothers].ToString().IndexOf("-") > 0 && colothers.ColumnName.ToString().IndexOf("Date") > -1)
                                                                        {
                                                                            string str4 = rowothers[colothers].ToString().Replace("-", "/");
                                                                            strInsert.Append(colothers.ColumnName + "-" + str4.ToString() + ";");
                                                                        }
                                                                        else
                                                                        {
                                                                            strInsert.Append(colothers.ColumnName + "-" + rowothers[colothers].ToString() + ";");
                                                                            if (colothers.ColumnName == "Ptn_pharmacy_pk")
                                                                            {
                                                                                iOldPtn_Pharmacy_Pk = Convert.ToInt32(rowothers[colothers]);

                                                                            }
                                                                            else if (colothers.ColumnName == "LabID")
                                                                            {
                                                                                iOldLabID = Convert.ToInt32(rowothers[colothers]);

                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }

                                                    }
                                                    ClsUtility.Init_Hashtable();
                                                    ClsUtility.AddParameters("@strinsert", SqlDbType.VarChar, strInsert.ToString());
                                                    ClsUtility.AddParameters("@Visit_pk", SqlDbType.Int, DRVisit_ID["Visit_Id"].ToString());
                                                    ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, theOtherDT.TableName.ToString());
                                                    ClsUtility.AddParameters("@NewPtn_Pk", SqlDbType.VarChar, DT.Rows[j]["NewPtn_Pk"].ToString());
                                                    ClsUtility.AddParameters("@VisitColumn", SqlDbType.VarChar, theOtherColName.ToString());
                                                    ClsUtility.AddParameters("@password", SqlDbType.VarChar, ApplicationAccess.DBSecurity);
                                                    DataRow theInsert = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientTableData_Futures", ClsUtility.ObjectEnum.DataRow);
                                                    if (theOtherDT.TableName.ToString() == "ORD_PATIENTPHARMACYORDER")
                                                    {
                                                        foreach (DataTable PharmacyDT in DSPharmacy.Tables)
                                                        {
                                                            DataView theOtherPharmacyDV = new DataView(PharmacyDT);
                                                            theOtherPharmacyDV.RowFilter = "Ptn_pharmacy_pk  = " + iOldPtn_Pharmacy_Pk.ToString();
                                                            DataTable theOtherPharmacyDT = CreateTableFromDataView(theOtherPharmacyDV);
                                                            if (theOtherPharmacyDT.Rows.Count > 0)
                                                            {

                                                                foreach (DataRow rowPharmacyothers in theOtherPharmacyDT.Rows)
                                                                {
                                                                    strInsert = new StringBuilder("");
                                                                    foreach (DataColumn colPhamothers in theOtherPharmacyDT.Columns)
                                                                    {
                                                                        if (rowPharmacyothers[colPhamothers] == DBNull.Value || rowPharmacyothers[colPhamothers].ToString() == "")
                                                                        {

                                                                            strInsert.Append(colPhamothers.ColumnName + "-NULL;");

                                                                        }
                                                                        else
                                                                        {
                                                                            if (colPhamothers.ColumnName.ToString() != "UpdateDate")
                                                                            {
                                                                                if (colPhamothers.ColumnName.ToString() == "CreateDate")
                                                                                {
                                                                                    strInsert.Append(colPhamothers.ColumnName + "-getdate();");

                                                                                }
                                                                                else
                                                                                {
                                                                                    if (rowPharmacyothers[colPhamothers].ToString().IndexOf("+05:30") > 0)
                                                                                    {
                                                                                        string str3 = rowPharmacyothers[colPhamothers].ToString().Substring(0, rowPharmacyothers[colPhamothers].ToString().IndexOf("T"));
                                                                                        str3 = str3.Replace("-", "/");
                                                                                        strInsert.Append(colPhamothers.ColumnName + "-" + str3.ToString() + ";");
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (rowPharmacyothers[colPhamothers].ToString().IndexOf("-") > 0 && colPhamothers.ColumnName.ToString().IndexOf("Date") > -1)
                                                                                        {
                                                                                            string str4 = rowPharmacyothers[colPhamothers].ToString().Replace("-", "/");
                                                                                            strInsert.Append(colPhamothers.ColumnName + "-" + str4.ToString() + ";");
                                                                                        }
                                                                                        else
                                                                                            strInsert.Append(colPhamothers.ColumnName + "-" + rowPharmacyothers[colPhamothers].ToString() + ";");
                                                                                    }
                                                                                }
                                                                            }
                                                                        }

                                                                    }
                                                                    ClsUtility.Init_Hashtable();
                                                                    ClsUtility.AddParameters("@strinsert", SqlDbType.VarChar, strInsert.ToString());
                                                                    ClsUtility.AddParameters("@Visit_pk", SqlDbType.Int, theInsert["Visit_Id"].ToString());
                                                                    ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, theOtherDT.TableName.ToString());
                                                                    ClsUtility.AddParameters("@NewPtn_Pk", SqlDbType.VarChar, DT.Rows[j]["NewPtn_Pk"].ToString());
                                                                    ClsUtility.AddParameters("@VisitColumn", SqlDbType.VarChar, "Ptn_pharmacy_pk");
                                                                    ClsUtility.AddParameters("@password", SqlDbType.VarChar, ApplicationAccess.DBSecurity);
                                                                    DataRow thePharmOthersId = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientTableData_Futures", ClsUtility.ObjectEnum.DataRow);

                                                                }
                                                            }

                                                        }

                                                    }///
                                                    else if (theOtherDT.TableName.ToString() == "ORD_PATIENTLABORDER")
                                                    {
                                                        foreach (DataTable LabDT in DSLaboratory.Tables)
                                                        {
                                                            DataView theOtherLabDV = new DataView(LabDT);
                                                            theOtherLabDV.RowFilter = theOtherColName.ToString() + " = " + iOldLabID.ToString();
                                                            DataTable theOtherPharmacyDT = CreateTableFromDataView(theOtherLabDV);
                                                            if (theOtherPharmacyDT.Rows.Count > 0)
                                                            {

                                                                foreach (DataRow rowPharmacyothers in theOtherPharmacyDT.Rows)
                                                                {
                                                                    strInsert = new StringBuilder("");
                                                                    foreach (DataColumn colPhamothers in theOtherPharmacyDT.Columns)
                                                                    {
                                                                        if (rowPharmacyothers[colPhamothers] == DBNull.Value || rowPharmacyothers[colPhamothers].ToString() == "")
                                                                        {

                                                                            strInsert.Append(colPhamothers.ColumnName + "-NULL;");

                                                                        }
                                                                        else
                                                                        {
                                                                            if (colPhamothers.ColumnName.ToString() != "UpdateDate")
                                                                            {
                                                                                if (colPhamothers.ColumnName.ToString() == "CreateDate")
                                                                                {
                                                                                    strInsert.Append(colPhamothers.ColumnName + "-getdate();");

                                                                                }
                                                                                else
                                                                                {
                                                                                    if (rowPharmacyothers[colPhamothers].ToString().IndexOf("+05:30") > 0)
                                                                                    {
                                                                                        string str3 = rowPharmacyothers[colPhamothers].ToString().Substring(0, rowPharmacyothers[colPhamothers].ToString().IndexOf("T"));
                                                                                        str3 = str3.Replace("-", "/");
                                                                                        strInsert.Append(colPhamothers.ColumnName + "-" + str3.ToString() + ";");
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (rowPharmacyothers[colPhamothers].ToString().IndexOf("-") > 0 && colPhamothers.ColumnName.ToString().IndexOf("Date") > -1)
                                                                                        {
                                                                                            string str4 = rowPharmacyothers[colPhamothers].ToString().Replace("-", "/");
                                                                                            strInsert.Append(colPhamothers.ColumnName + "-" + str4.ToString() + ";");
                                                                                        }
                                                                                        else
                                                                                            strInsert.Append(colPhamothers.ColumnName + "-" + rowPharmacyothers[colPhamothers].ToString() + ";");
                                                                                    }
                                                                                }
                                                                            }
                                                                        }

                                                                    }
                                                                    ClsUtility.Init_Hashtable();
                                                                    ClsUtility.AddParameters("@strinsert", SqlDbType.VarChar, strInsert.ToString());
                                                                    ClsUtility.AddParameters("@Visit_pk", SqlDbType.Int, theInsert["Visit_Id"].ToString());
                                                                    ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, theOtherDT.TableName.ToString());
                                                                    ClsUtility.AddParameters("@NewPtn_Pk", SqlDbType.VarChar, DT.Rows[j]["NewPtn_Pk"].ToString());
                                                                    ClsUtility.AddParameters("@VisitColumn", SqlDbType.VarChar, "LabID");
                                                                    ClsUtility.AddParameters("@password", SqlDbType.VarChar, ApplicationAccess.DBSecurity);
                                                                    DataRow theLabOthersId = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientTableData_Futures", ClsUtility.ObjectEnum.DataRow);

                                                                }
                                                            }

                                                        }

                                                    }///

                                                    /////////////////////////////////////////
                                                }
                                            }
                                        }//////
                                    }

                                }
                                if (dsImportPatData.Tables.Contains("DTL_PATIENTTRACKINGCARE"))
                                {
                                    DataRow DRTracking_ID;
                                    DataTable theDTFilteredTrackMstVisitName = new DataTable();
                                    DataView theDtlTrackDV = new DataView(dsImportPatData.Tables["DTL_PATIENTTRACKINGCARE"]);
                                    theDtlTrackDV.RowFilter = "Ptn_pk=" + DT.Rows[j]["OldPtn_Pk"].ToString();
                                    DataTable theFilteredDtlTrack = CreateTableFromDataView(theDtlTrackDV);
                                    foreach (DataRow DRDtlTrack in theFilteredDtlTrack.Rows)
                                    {
                                        strInsert = new StringBuilder("");
                                        if (DSVisitTypes.Tables[1].Rows.Count > 0)
                                        {
                                            DataView theTrackMstModuleDV = new DataView(dsImportPatData.Tables["MST_MODULE"]);
                                            theTrackMstModuleDV.RowFilter = "ModuleId=" + DRDtlTrack["ModuleId"].ToString();
                                            DataTable theFilteredTrackMstModuleDT = CreateTableFromDataView(theTrackMstModuleDV);
                                            if (theFilteredTrackMstModuleDT.Rows.Count > 0)
                                            {
                                                DataView theFilteredTrackMstModuleDV = new DataView(DSVisitTypes.Tables[1]);
                                                theFilteredTrackMstModuleDV.RowFilter = "ModuleName='" + theFilteredTrackMstModuleDT.Rows[0]["ModuleName"].ToString() + "'";
                                                theDTFilteredTrackMstVisitName = CreateTableFromDataView(theFilteredTrackMstModuleDV);
                                            }
                                        }
                                        foreach (DataColumn LnkTrackcol in theFilteredDtlTrack.Columns)
                                        {
                                            //test for null here
                                            if (DRDtlTrack[LnkTrackcol] == DBNull.Value || DRDtlTrack[LnkTrackcol].ToString() == "")
                                            {

                                                strInsert.Append(LnkTrackcol.ColumnName + "-NULL;");

                                            }
                                            else
                                            {
                                                if (LnkTrackcol.ColumnName.ToString() != "UpdateDate")
                                                {
                                                    if (LnkTrackcol.ColumnName.ToString() == "CreateDate")
                                                    {
                                                        strInsert.Append(LnkTrackcol.ColumnName + "-getdate();");

                                                    }
                                                    else
                                                    {
                                                        if (DRDtlTrack[LnkTrackcol].ToString().IndexOf("+05:30") > 0)
                                                        {
                                                            string str2 = DRDtlTrack[LnkTrackcol].ToString().Substring(0, DRDtlTrack[LnkTrackcol].ToString().IndexOf("T"));
                                                            str2 = str2.Replace("-", "/");
                                                            strInsert.Append(LnkTrackcol.ColumnName + "-" + str2.ToString() + ";");
                                                        }
                                                        else
                                                        {
                                                            strInsert.Append(LnkTrackcol.ColumnName + "-" + DRDtlTrack[LnkTrackcol].ToString() + ";");
                                                            if (LnkTrackcol.ColumnName == "TrackingId")
                                                            {
                                                                iOldTrackingId = Convert.ToInt32(DRDtlTrack[LnkTrackcol]);
                                                            }

                                                        }
                                                    }
                                                }

                                            }

                                        }
                                        ClsUtility.Init_Hashtable();
                                        ClsUtility.AddParameters("@strinsert", SqlDbType.VarChar, strInsert.ToString());
                                        ClsUtility.AddParameters("@Visit_pk", SqlDbType.Int, theDTFilteredTrackMstVisitName.Rows[0]["ModuleId"].ToString());
                                        ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, theFilteredDtlTrack.TableName.ToString());
                                        ClsUtility.AddParameters("@NewPtn_Pk", SqlDbType.Int, DT.Rows[j]["NewPtn_Pk"].ToString());
                                        ClsUtility.AddParameters("@VisitColumn", SqlDbType.VarChar, "ModuleId");
                                        ClsUtility.AddParameters("@password", SqlDbType.VarChar, ApplicationAccess.DBSecurity);
                                        DRTracking_ID = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientTableData_Futures", ClsUtility.ObjectEnum.DataRow);
                                        if (DRTracking_ID["Visit_Id"].ToString() == "9999999")
                                        {
                                            break;
                                        }
                                        if (dsImportPatData.Tables.Contains("DTL_PATIENTCAREENDED"))
                                        {

                                            //DataTable theDTFilteredTrackMstVisitName = new DataTable();
                                            DataView theDtlCareEndDV = new DataView(dsImportPatData.Tables["DTL_PATIENTCAREENDED"]);
                                            theDtlCareEndDV.RowFilter = "Ptn_pk=" + DT.Rows[j]["OldPtn_Pk"].ToString() + " and TrackingId=" + iOldTrackingId.ToString();
                                            DataTable theFilteredDtlCareEnd = CreateTableFromDataView(theDtlCareEndDV);
                                            foreach (DataRow DRDtlCareEnd in theFilteredDtlCareEnd.Rows)
                                            {
                                                strInsert = new StringBuilder("");
                                                foreach (DataColumn LnkCareEndcol in theFilteredDtlTrack.Columns)
                                                {
                                                    //test for null here
                                                    if (DRDtlCareEnd[LnkCareEndcol] == DBNull.Value || DRDtlCareEnd[LnkCareEndcol].ToString() == "")
                                                    {

                                                        strInsert.Append(LnkCareEndcol.ColumnName + "-NULL;");

                                                    }
                                                    else
                                                    {
                                                        if (LnkCareEndcol.ColumnName.ToString() != "UpdateDate")
                                                        {
                                                            if (LnkCareEndcol.ColumnName.ToString() == "CreateDate")
                                                            {
                                                                strInsert.Append(LnkCareEndcol.ColumnName + "-getdate();");

                                                            }
                                                            else
                                                            {
                                                                if (DRDtlCareEnd[LnkCareEndcol].ToString().IndexOf("+05:30") > 0)
                                                                {
                                                                    string str2 = DRDtlCareEnd[LnkCareEndcol].ToString().Substring(0, DRDtlCareEnd[LnkCareEndcol].ToString().IndexOf("T"));
                                                                    str2 = str2.Replace("-", "/");
                                                                    strInsert.Append(LnkCareEndcol.ColumnName + "-" + str2.ToString() + ";");
                                                                }
                                                                else
                                                                {
                                                                    strInsert.Append(LnkCareEndcol.ColumnName + "-" + DRDtlCareEnd[LnkCareEndcol].ToString() + ";");
                                                                    if (LnkCareEndcol.ColumnName == "CareEndedId")
                                                                    {
                                                                        iOldCareEnded = Convert.ToInt32(DRDtlCareEnd[LnkCareEndcol]);
                                                                    }
                                                                }
                                                            }
                                                        }

                                                    }

                                                }
                                                ClsUtility.Init_Hashtable();
                                                ClsUtility.AddParameters("@strinsert", SqlDbType.VarChar, strInsert.ToString());
                                                ClsUtility.AddParameters("@Visit_pk", SqlDbType.Int, DRTracking_ID["Visit_Id"].ToString());
                                                ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, theFilteredDtlCareEnd.TableName.ToString());
                                                ClsUtility.AddParameters("@NewPtn_Pk", SqlDbType.Int, DT.Rows[j]["NewPtn_Pk"].ToString());
                                                ClsUtility.AddParameters("@VisitColumn", SqlDbType.VarChar, "TrackingId");
                                                ClsUtility.AddParameters("@password", SqlDbType.VarChar, ApplicationAccess.DBSecurity);
                                                DataRow DRCareEnded_ID = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientTableData_Futures", ClsUtility.ObjectEnum.DataRow);
                                                if (dsImportPatData.Tables.Contains("DTL_PATIENTCARERESTARTED") && DRCareEnded_ID["Visit_Id"].ToString() != "9999999")
                                                {

                                                    //DataTable theDTFilteredTrackMstVisitName = new DataTable();
                                                    DataView theDtlCareRESTARTDV = new DataView(dsImportPatData.Tables["DTL_PATIENTCARERESTARTED"]);
                                                    theDtlCareRESTARTDV.RowFilter = "Ptn_pk=" + DT.Rows[j]["OldPtn_Pk"].ToString() + " and CareEndedId=" + iOldCareEnded.ToString();
                                                    DataTable theFilteredDtlCareRestart = CreateTableFromDataView(theDtlCareRESTARTDV);
                                                    foreach (DataRow DRDtlCareRestart in theFilteredDtlCareRestart.Rows)
                                                    {
                                                        strInsert = new StringBuilder("");
                                                        foreach (DataColumn CareRestartcol in theFilteredDtlCareRestart.Columns)
                                                        {
                                                            //test for null here
                                                            if (DRDtlCareRestart[CareRestartcol] == DBNull.Value || DRDtlCareRestart[CareRestartcol].ToString() == "")
                                                            {

                                                                strInsert.Append(CareRestartcol.ColumnName + "-NULL;");

                                                            }
                                                            else
                                                            {
                                                                if (CareRestartcol.ColumnName.ToString() != "UpdateDate")
                                                                {
                                                                    if (CareRestartcol.ColumnName.ToString() == "CreateDate")
                                                                    {
                                                                        strInsert.Append(CareRestartcol.ColumnName + "-getdate();");

                                                                    }
                                                                    else
                                                                    {
                                                                        if (DRDtlCareRestart[CareRestartcol].ToString().IndexOf("+05:30") > 0)
                                                                        {
                                                                            string str2 = DRDtlCareRestart[CareRestartcol].ToString().Substring(0, DRDtlCareRestart[CareRestartcol].ToString().IndexOf("T"));
                                                                            str2 = str2.Replace("-", "/");
                                                                            strInsert.Append(CareRestartcol.ColumnName + "-" + str2.ToString() + ";");
                                                                        }
                                                                        else
                                                                            strInsert.Append(CareRestartcol.ColumnName + "-" + DRDtlCareRestart[CareRestartcol].ToString() + ";");
                                                                    }
                                                                }

                                                            }

                                                        }
                                                        ClsUtility.Init_Hashtable();
                                                        ClsUtility.AddParameters("@strinsert", SqlDbType.VarChar, strInsert.ToString());
                                                        ClsUtility.AddParameters("@Visit_pk", SqlDbType.Int, DRCareEnded_ID["Visit_Id"].ToString());
                                                        ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, theFilteredDtlCareRestart.TableName.ToString());
                                                        ClsUtility.AddParameters("@NewPtn_Pk", SqlDbType.Int, DT.Rows[j]["NewPtn_Pk"].ToString());
                                                        ClsUtility.AddParameters("@VisitColumn", SqlDbType.VarChar, "CareEndedId");
                                                        ClsUtility.AddParameters("@password", SqlDbType.VarChar, ApplicationAccess.DBSecurity);
                                                        DataRow DRCareRestart_ID = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientTableData_Futures", ClsUtility.ObjectEnum.DataRow);

                                                    }

                                                }
                                                DataSet DSCareEndedId = GetDSbyColumnName(dsImportPatData, "CareEndedId", true);
                                                foreach (DataTable DTCareEndedID in DSCareEndedId.Tables)
                                                {
                                                    if (DTCareEndedID.TableName.ToString() != "DTL_PATIENTCARERESTARTED" && DTCareEndedID.TableName.ToString() != "DTL_PATIENTCAREENDED")
                                                    {
                                                        DataTable theFilteredCareEndedIdDT = new DataTable();
                                                        DataView theCareEndedIdDV = new DataView(DTCareEndedID);
                                                        theCareEndedIdDV.RowFilter = "Ptn_pk=" + DT.Rows[j]["OldPtn_Pk"].ToString() + " and CareEndedId=" + DRCareEnded_ID["Visit_Id"].ToString();
                                                        theFilteredCareEndedIdDT = CreateTableFromDataView(theCareEndedIdDV);
                                                        foreach (DataRow DRCareEndedId in theFilteredCareEndedIdDT.Rows)
                                                        {
                                                            strInsert = new StringBuilder("");
                                                            foreach (DataColumn CareEndedIdcol in theFilteredCareEndedIdDT.Columns)
                                                            {
                                                                //test for null here
                                                                if (DRCareEndedId[CareEndedIdcol] == DBNull.Value || DRCareEndedId[CareEndedIdcol].ToString() == "")
                                                                {

                                                                    strInsert.Append(CareEndedIdcol.ColumnName + "-NULL;");

                                                                }
                                                                else
                                                                {
                                                                    if (CareEndedIdcol.ColumnName.ToString() != "UpdateDate")
                                                                    {
                                                                        if (CareEndedIdcol.ColumnName.ToString() == "CreateDate")
                                                                        {
                                                                            strInsert.Append(CareEndedIdcol.ColumnName + "-getdate();");

                                                                        }
                                                                        else
                                                                        {
                                                                            if (DRCareEndedId[CareEndedIdcol].ToString().IndexOf("+05:30") > 0)
                                                                            {
                                                                                string str2 = DRCareEndedId[CareEndedIdcol].ToString().Substring(0, DRCareEndedId[CareEndedIdcol].ToString().IndexOf("T"));
                                                                                str2 = str2.Replace("-", "/");
                                                                                strInsert.Append(CareEndedIdcol.ColumnName + "-" + str2.ToString() + ";");
                                                                            }
                                                                            else
                                                                                strInsert.Append(CareEndedIdcol.ColumnName + "-" + DRCareEndedId[CareEndedIdcol].ToString() + ";");
                                                                        }
                                                                    }

                                                                }

                                                            }
                                                            ClsUtility.Init_Hashtable();
                                                            ClsUtility.AddParameters("@strinsert", SqlDbType.VarChar, strInsert.ToString());
                                                            ClsUtility.AddParameters("@Visit_pk", SqlDbType.Int, DRCareEnded_ID["Visit_Id"].ToString());
                                                            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, theFilteredCareEndedIdDT.TableName.ToString());
                                                            ClsUtility.AddParameters("@NewPtn_Pk", SqlDbType.Int, DT.Rows[j]["NewPtn_Pk"].ToString());
                                                            ClsUtility.AddParameters("@VisitColumn", SqlDbType.VarChar, "CareEndedId");
                                                            ClsUtility.AddParameters("@password", SqlDbType.VarChar, ApplicationAccess.DBSecurity);
                                                            DataRow DRCareRestart_ID = (DataRow)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_ImportPatientTableData_Futures", ClsUtility.ObjectEnum.DataRow);

                                                        }

                                                    }
                                                }
                                            }


                                        }
                                    }


                                }

                            }

                        }
                    }
                }



                DataMgr.CommitTransaction(this.Transaction);
                DataMgr.ReleaseConnection(this.Connection);
                //return iFeatureId;
                return DT;
            }
            catch (Exception ex)
            {
                DataMgr.RollBackTransation(this.Transaction);
                throw ex;
            }
            finally
            {
                if (this.Connection != null)
                    DataMgr.ReleaseConnection(this.Connection);

            }
        }
        public DataTable CreateTableFromDataView(DataView obDataView)
        {
            DataTable obNewDt = null;
            if (obDataView.Table != null)
            {
                obNewDt = obDataView.Table.Clone();
                int idx = 0;
                string[] strColNames = new string[obNewDt.Columns.Count];
                foreach (DataColumn col in obNewDt.Columns)
                {
                    strColNames[idx++] = col.ColumnName;
                }

                IEnumerator viewEnumerator = obDataView.GetEnumerator();
                while (viewEnumerator.MoveNext())
                {
                    DataRowView drv = (DataRowView)viewEnumerator.Current;
                    DataRow dr = obNewDt.NewRow();
                    foreach (string strName in strColNames)
                    {
                        dr[strName] = drv[strName];
                    }
                    obNewDt.Rows.Add(dr);
                }
                return obNewDt;
            }
            return obNewDt;
        }

        private DataSet GetDSbyColumnName(DataSet dsinput, string colname, bool isLike)
        {
            DataSet dsRet = new DataSet();
            for (int i = 0; i < dsinput.Tables.Count; i++)
            {
                if ((dsinput.Tables[i].TableName != "MST_VISITTYPE") && (dsinput.Tables[i].TableName != "ORD_VISIT"))
                {
                    for (int j = 0; j < dsinput.Tables[i].Columns.Count; j++)
                    {
                        if (isLike)
                        {
                            if (dsinput.Tables[i].Columns[j].ColumnName.Contains(colname))
                            {
                                dsRet.Tables.Add(dsinput.Tables[i].Copy());
                            }

                        }
                        else
                        {
                            if (dsinput.Tables[i].Columns[j].ColumnName == colname)
                            {
                                dsRet.Tables.Add(dsinput.Tables[i].Copy());
                            }
                        }
                    }
                }
            }

            return dsRet;

        }

        public void GetExportDataDump(DateTime frmDate, DateTime ToDate, String location)
        {
            string locationName = string.Empty;
            ClsUtility.Init_Hashtable();
            ClsObject theDataDump = new ClsObject();
            ClsUtility.AddParameters("@FrmDate", SqlDbType.VarChar, frmDate.ToString());
            ClsUtility.AddParameters("@ToDate", SqlDbType.VarChar, ToDate.ToString());
            ClsUtility.AddParameters("@Location", SqlDbType.VarChar, location);
            DataSet theDS = (DataSet)theDataDump.ReturnObject(ClsUtility.theParams, "Pr_Admin_ExportDataDump", ClsUtility.ObjectEnum.DataSet);
            foreach (DataTable theDT in theDS.Tables)
            {
                theDT.TableName = theDT.Columns[0].ColumnName.ToString();
                if (theDT.TableName == "mst_Facility")
                {
                    locationName = theDT.Rows[0]["facilityname"].ToString().Trim().Replace(' ', '_');
                }

                theDT.Columns.RemoveAt(0);

            }
            if (locationName != "")
            {
                theDS.WriteXml("C:\\IQCareData_" + locationName + ".xml", XmlWriteMode.WriteSchema);
            }
            else
            {
                theDS.WriteXml("C:\\IQCareDataDump.xml", XmlWriteMode.WriteSchema);
            }

        }

        public DataSet ReturnQueryResult(string theQuery)
        {
            ClsObject theQB = new ClsObject();
            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@QryString", SqlDbType.VarChar, theQuery);
            return (DataSet)theQB.ReturnObject(ClsUtility.theParams, "pr_General_SQL_Parse", ClsUtility.ObjectEnum.DataSet);
        }

        public void InsertBulk(DataTable theDT)
        {
            SqlConnection theCnn = (SqlConnection)DataMgr.GetConnection();
            SqlBulkCopy theBulk = new SqlBulkCopy(theCnn);
            try
            {

                theBulk.DestinationTableName = "[IQCare_Tmp].[dbo]." + theDT.TableName;
                theBulk.WriteToServer(theDT);
                theDT = null;
                theBulk.Close();
                theBulk = null;
                theCnn.Close();
                theCnn.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                if (theCnn != null)
                {
                    if (theCnn.State != ConnectionState.Closed)
                    {
                        Marshal.ReleaseComObject(theCnn);

                        // theCnn.Close();
                    }
                    //Marshal.ReleaseComObject(theCnn);
                    theCnn = null;
                }
                if (theBulk != null)
                {
                    // theBulk.Close();
                    Marshal.ReleaseComObject(theBulk);
                    theBulk = null;
                }

            }
        }
        public int ImportDatabase()
        {
            //try
            //{
            //    this.Connection = DataMgr.GetConnection();
            //    this.Transaction = DataMgr.BeginTransaction(this.Connection);

            //    ClsObject FormDetail = new ClsObject();
            //    FormDetail.Connection = this.Connection;
            //    int theRowAffected = 0;
            //    ClsUtility.Init_Hashtable();
            //    theRowAffected = (int)FormDetail.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportDatabase_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);
            //    return theRowAffected;
            //}
            //catch
            //{
            //    return 0;

            //}
            //finally
            //{
            //    if (this.Connection != null)
            //        DataMgr.ReleaseConnection(this.Connection);

            //}
            // try
            // {
            int theRowAffected = 0;
            ClsObject imptab = new ClsObject();
            ClsUtility.Init_Hashtable();
            DataTable theDT = (DataTable)imptab.ReturnObject(ClsUtility.theParams, "SELECT DB_NAME()", ClsUtility.ObjectEnum.DataTable);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_Import_SyncTableStructure", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Facility");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Module");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);




            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "mst_Groups");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);



            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Feature");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //theRowAffected = (Int32)
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Occupation");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "mst_homepage");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);



            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "dtl_homepage");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //theRowAffected = (Int32)
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Section");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            // theRowAffected = (Int32)
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_PatientIdentifier");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "lnk_PatientModuleIdentifier");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "lnk_GroupFeatures");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Patient");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Visittype");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Ord_Visit");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_employee");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "ord_PatientPharmacyOrder");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "dtl_PatientPharmacyOrder");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "dtl_PatientPharmacyOrderNonARV");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "ord_PatientLabOrder");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "dtl_PatientLabResults");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);



            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "lnk_FacilityModule");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Lnk_PatientProgramStart");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "mst_code");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_DeCode");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Lnk_ProgramExitReasons");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_ModCode");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_ModDeCode");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);



            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "mst_CustomField");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_CustomFormField");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "lnk_forms_00");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "lnk_forms_01");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


           

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "dtl_PatientAppointment");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_user");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Lnk_CareEndForm");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "lnk_ConditionalFields");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "lnk_CareEndConditionalFields");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "lnk_fieldsBusinessRule");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "dtl_patienthomevisit");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);



            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "dtl_PatientTrackingCare");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);



            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "dtl_PatientCareEnded");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertCustomFormData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);





            //   ClsUtility.Init_Hashtable();
            ////   theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportedDataCustomTableCreation_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);
            //   theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportedDataCustomTableCreation_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ////ClsUtility.Init_Hashtable();
            ////ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ////ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //////theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportData_Sanjay", ClsUtility.ObjectEnum.ExecuteNonQuery);
            ////imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportData_CustomField", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //  theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportCareEndedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportCareEndedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());

            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportData_Sanjay_new", ClsUtility.ObjectEnum.ExecuteNonQuery);


            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportData_Sanjay", ClsUtility.ObjectEnum.ExecuteNonQuery);
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportData_Sanjay", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "dtl_PatientDisclosure");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExported_DTLTable_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@FrmDb", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportData_Sanjay", ClsUtility.ObjectEnum.ExecuteNonQuery);
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportedDataCustomTbl_Fb_TableCreation_MultiSelect_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@FrmDb", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportData_Sanjay", ClsUtility.ObjectEnum.ExecuteNonQuery);
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_ImportedDataCustomTableCreation_Futures_New", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "dtl_PatientHouseHoldInfo");
            ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);



            // SCM TABLE AND DATA


            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Store");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Supplier");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Batch");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_DispensingUnit");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "mst_Donor");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_Manufacturer");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "Mst_program");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "mst_Drug");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "mst_Frequency");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "mst_Strength");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "mst_Generic");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);

            //ClsUtility.Init_Hashtable();
            //ClsUtility.AddParameters("@TableName", SqlDbType.VarChar, "mst_DrugType");
            //ClsUtility.AddParameters("@FromDB", SqlDbType.VarChar, "IQCare_Tmp");
            //ClsUtility.AddParameters("@ToDB", SqlDbType.VarChar, theDT.Rows[0][0].ToString());
            //imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_InsertExportedData_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);


            ClsUtility.Init_Hashtable();
            theRowAffected = (Int32)imptab.ReturnObject(ClsUtility.theParams, "Pr_Admin_DropDBColumns_Futures", ClsUtility.ObjectEnum.ExecuteNonQuery);



            ////  if (theRowAffected == 0)
            ////  {
            ////      MsgBuilder theMsg = new MsgBuilder();
            ////      theMsg.DataElements["MessageText"] = "Error. Try Again..";
            ////      AppException.Create("#C1", theMsg);

            ////  }
            return theRowAffected;
            ////}
            ////catch
            ////{
            ////    return 0;

            ////}

        }

    }
}
